import {
  PageListType,
  getsupervisionProject, //巡查项目下拉
  getsupervisionList, //监管列表下拉框
  getgroupByGrid, //网格区域统计
  getgroupByTerminal, //航站楼统计
  supervisionCreator, //创建人
} from "@/api/construction/projectSupervise";
import { computed, ref } from "vue";

export const supervisionIdData: any = ref([]);
export const creatorData: any = ref([]);
export const sprojectIdData: any = ref([]);
export const terminalsData: any = ref([]);
export const gridIdsData: any = ref([]);

//监管列表下拉框
export const getCreateUserOrgIdData = () => {
  getsupervisionList()
    .then((res) => {
      return (supervisionIdData.value = res.data.map(
        (itemu: { name: any; id: any }) => {
          return { label: itemu.name, value: itemu.id };
        }
      ));
    })
    .catch(() => {
      return (supervisionIdData.value = []);
    });
};
//项目编号
export const getsprojectIdData = () => {
  getsupervisionProject()
    .then((res) => {
      // console.log("res---", res);
      sprojectIdData.value = res.data.map((itemu: { id: any; name: any }) => {
        return { label: itemu.name, value: itemu.id };
      });
      // console.log(" sprojectIdData.value", sprojectIdData.value);

      return (sprojectIdData.value = sprojectIdData.value);
    })
    .catch(() => {
      return (sprojectIdData.value = []);
    });
};

//航站楼
export const getterminalsData = () => {
  getgroupByTerminal()
    .then((res) => {
      return (terminalsData.value = res.data.map(
        (itemu: { location: any; count: any }) => {
          return { label: itemu.location + itemu.count, value: itemu.location };
        }
      ));
    })
    .catch(() => {
      return (terminalsData.value = []);
    });
};
//网格区域
export const getgridIdsData = () => {
  getgroupByGrid()
    .then((res) => {
      return (gridIdsData.value = res.data.map(
        (itemu: { location: any; count: any }) => {
          return { label: '全部' + itemu.count, value: itemu.count };
        }
      ));
    })
    .catch(() => {
      return (gridIdsData.value = []);
    });
};
//创建人
export const getcreatorData = async () => {
  supervisionCreator()
    .then((res) => {
      return (creatorData.value = res.data.map(
        (itemu: { name: any; id: any }) => {
          return { label: itemu.name, value: itemu.id };
        }
      ));
    })
    .catch(() => {
      return (creatorData.value = []);
    });
};
